package info.openlvb.openlvg.client.handler;

import java.util.Date;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.datepicker.client.DatePicker;
import com.gwtext.client.widgets.Window;

public class DatePickerListenner implements ClickHandler {
	
	private CallPersoGraphListenner CPGListenner;
	private String dateSource;
	public DatePickerListenner(CallPersoGraphListenner CPGListenner,String dateSource){
		this.CPGListenner = CPGListenner;
		this.dateSource = dateSource;
	}
	public void onClick(ClickEvent event) {
		final Window window = new Window();
		DatePicker Date = new DatePicker();
		window.setModal(true);
		window.add(Date);
		Button closeButton = new Button("CLOSE",
				new ClickHandler() {
			public void onClick(ClickEvent event) {
				window.hide();
			}
		});
		Date.addValueChangeHandler(new ValueChangeHandler() {
			public void onValueChange(ValueChangeEvent event) {
				if(dateSource.equals("Date1")){
					CPGListenner.setDate1((Date)event.getValue());
					CPGListenner.setTextDateBox1(DateTimeFormat.getFormat("dd/MM/yy").format((Date)event.getValue()));

				}
				else {
					CPGListenner.setDate2((Date)event.getValue());
					CPGListenner.setTextDateBox2(DateTimeFormat.getFormat("dd/MM/yy").format((Date)event.getValue()));

				}
				window.hide();
			}
		});
		window.show();
	}
}
